﻿/*
    未登录和登陆都需要用到的一些js方法.
 */

var navItemActive = function(object) {

}

function getCookie(c_name) {
    if (document.cookie.length>0)
    {
        var c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}

function setCookie(c_name,value,expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name + "=" + escape(value) +
        ((expiredays==null) ? "" : "; expires=" + exdate.toGMTString());
}

function checkCookie() {
    var username=getCookie('username')
    if (username!=null && username!="")
    {alert('Welcome again '+username+'!')}
    else
    {
        username=prompt('Please enter your name:',"")
        if (username!=null && username!="")
        {
            setCookie('username',username,365);
        }
    }
}


var horizontalForm = function(options) {
    var style = options.style;
    var legend = options.title;
    var input = options.input;
    var html = '<form class="form-horizontal ' + style + '"><legend>';

    html += legend;
    html += '</legend><fieldset>';
    $.each(input,function(k,v){
        html += '<div class="form-group">';
        html += '<lable class="col-md-4 control-label">' + v.name + '</lable>';
        html += '<div class="col-md-8"><input class="form-control" ';
        $.each(v.attr,function(k,v){
            html += k + "=" + v + ' ';
        });
        html += '"></div></div>';
    });
    html += '</fieldset></form>';
    return $(html);
};
